<template>
  <h1>循环指令</h1>
  <li v-for="item in 5">Hello{{item}}</li>
  <hr>
  <ul v-for="item in 3">
    <li>hello{{item}}</li>
    <li>hello{{item}}</li>
    <li>hello{{item}}</li>
  </ul>
  <table border="1">
    <tr>
      <th>商品编号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品数量</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
  import {ref} from "vue";
// 定义响应式数组
  const productArr = ref([
    {title:"葡萄", price:10, num:100},
    {title:"苹果", price:20, num:200},
    {title:"西瓜", price:30, num:300},
    {title:"香蕉", price:40, num:400}
  ]);
  // 定义删除商品的方法
  const del = (index) => {
    productArr.value.splice(index,1);
  }
</script>

<style scoped>

</style>
